package com.fjec.market.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fjec.common.Const;
import com.fjec.common.enums.EnumSysCode;
import com.fjec.common.jxls.DataSixUpload;
import com.fjec.common.protocol.JsonResult;
import com.fjec.common.shiro.AccountInfo;
import com.fjec.common.util.*;
import com.fjec.common.view.AnnexBizItem;
import com.fjec.common.ys.PaidHelper;
import com.fjec.common.ys.PositionConfig;
import com.fjec.common.ys.YsProperties;
import com.fjec.common.ys.protocol.*;
import com.fjec.market.entity.*;
import com.fjec.market.feign.BaseClient;
import com.fjec.market.mapper.InfoBusinessMapper;
import com.fjec.market.mapper.InfoFarmerMapper;
import com.fjec.market.mapper.InfoYsepayRegisterMapper;
import com.fjec.market.rabbitmq.provider.SysMsgProvider;
import com.fjec.market.rabbitmq.provider.YsRegProvider;
import com.fjec.market.rabbitmq.provider.YsRegisterResultQueryProvider;
import com.fjec.market.service.IBizServOrderService;
import com.fjec.market.service.IBizSubServOrderService;
import com.fjec.market.service.IBizYespayRegLogService;
import com.fjec.market.service.IInfoYsepayRegisterService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjec.market.view.InfoYseapyRegVO;
import com.fjec.market.view.YsOffLineRegVO;
import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.awt.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.List;

/**
 * <p>
 * 052.银盛支付注册表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2020-10-30
 */
@Service
public class InfoYsepayRegisterServiceImpl extends ServiceImpl<InfoYsepayRegisterMapper, InfoYsepayRegister> implements IInfoYsepayRegisterService {

    @Resource
    private InfoYsepayRegisterMapper mapper;

    @Resource
    private InfoFarmerMapper farmerMapper;

    @Resource
    private InfoBusinessMapper businessMapper;

    @Resource
    private SequenceIdGenerator idGenerator;

    @Resource
    private BaseClient baseClient;

    @Resource
    private YsRegProvider ysRegProvider;

    @Resource
    private YsProperties ysProperties;

    @Resource
    private PaidHelper paidHelper;

    @Autowired
    private SysMsgProvider sysMsgProvider;

    @Autowired
    private YsRegisterResultQueryProvider ysRegisterResultQueryProvider;

    @Resource
    private IBizYespayRegLogService bizYespayRegLogService;

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public JsonResult savePersonalRegInfo(String custName, String idCardNum, String bankType,
                                          String provMap, String cityMap, String countyMap, String address,
                                          String bankProvMap, String bankCityMap, String bankCountyMap,
                                          String bankMap, String bankCardNum, String bankPhone,
                                          Long id102, String url102, Long id103, String url103,
                                          Long id104, String url104, Long id105, String url105,
                                          Long id106, String url106, String id107, String url107,
                                          String legalCertExpire) {
        Integer busiType = AccountInfo.getBusiType();
        Long busiId = AccountInfo.getBusiId();
        String shopName = AccountInfo.getShopName();
        // check 是否已完善信息
        Integer regStatus = 0;
        switch (busiType) {
            case 2:
                InfoFarmer farmer = farmerMapper.selectById(busiId);
                if (farmer != null) {
                    regStatus = farmer.getRegStatus();
                }
                break;
            case 3:
            case 4:
            case 5:
                InfoBusiness business = businessMapper.selectById(busiId);
                if (business != null) {
                    regStatus = business.getRegStatus();
                }
                break;
        }
        if (regStatus != 2) {
            return JsonResult.failure()
                    .code(EnumSysCode.ERR_3021.getCode())
                    .message(EnumSysCode.ERR_3021.getMsg())
                    .build();
        }
        //
        InfoYsepayRegister entity = new InfoYsepayRegister();
        Long entityId = idGenerator.nextId();
        // 保存
        entity.setId(entityId);
        entity.setBusiType(busiType);
        entity.setBusiId(busiId);
        entity.setUserId(AccountInfo.getUserId());
        entity.setOpenId(AccountInfo.getOpenId());
        entity.setCustType("O");
        entity.setAnotherName(shopName);
        entity.setCustName(custName);
        entity.setMerFlag("11");
        entity.setIndustry("58");
        // 地址
        entity.setProvince(JsonUtil.jsonToMap(BizUtil.quot2Sign(provMap)));
        entity.setCity(JsonUtil.jsonToMap(BizUtil.quot2Sign(cityMap)));
        entity.setCounty(JsonUtil.jsonToMap(BizUtil.quot2Sign(countyMap)));
        entity.setCompanyAddr(address);
        // 法人
        entity.setLegalTel(bankPhone);
        entity.setLegalCertType("00");
        entity.setLegalCertNo(idCardNum);
        entity.setLegalCertExpire(legalCertExpire);
        // 银行
        entity.setSettleType("1");
        entity.setBankAccountNo(bankCardNum);
        entity.setBankAccountName(custName);
        entity.setBankAccountType("personal");
        entity.setBankCardType("debit");
        Map<String, Object> tmpMap = JsonUtil.jsonToMap(BizUtil.quot2Sign(bankMap));
        entity.setBankCode(MapUtils.getString(tmpMap, "key"));
        entity.setBankName(MapUtils.getString(tmpMap, "text"));
        entity.setBankType(bankType);
        entity.setBankProvince(JsonUtil.jsonToMap(BizUtil.quot2Sign(bankProvMap)));
        entity.setBankCity(JsonUtil.jsonToMap(BizUtil.quot2Sign(bankCityMap)));
        entity.setCertType("00");
        entity.setCertNo(idCardNum);
        entity.setBankTelephoneNo(bankPhone);
        // 状态
        entity.setRegStatus(1);
        entity.setCreateTime(DateUtil.nowLdt());
        // 附件处理
        List<AnnexBizItem> annexBizItemList = new ArrayList<>();
        // 整理进件相关图片
        List<Map<String, Object>> picMapList = new ArrayList<>();
        // 102 身份证正面
        Map<String, Object> picMap = new HashMap<>();
        picMap.put("type", 102);
        picMap.put("id", id102);
        picMap.put("url", url102);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id102), entityId, 102));
        // 103 身份证反面
        picMap = new HashMap<>();
        picMap.put("type", 103);
        picMap.put("id", id103);
        picMap.put("url", url103);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id103), entityId, 103));
        // 104 银行卡正面
        picMap = new HashMap<>();
        picMap.put("type", 104);
        picMap.put("id", id104);
        picMap.put("url", url104);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id104), entityId, 104));
        // 105 银行卡反面
        picMap = new HashMap<>();
        picMap.put("type", 105);
        picMap.put("id", id105);
        picMap.put("url", url105);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id105), entityId, 105));
        // 106 手持身份证
        picMap = new HashMap<>();
        picMap.put("type", 106);
        picMap.put("id", id106);
        picMap.put("url", url106);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id106), entityId, 106));
        // 107 经营场所照片列表
        String[] ids = id107.split(",");
        String[] urls = url107.split(",");
        for (int i = 0; i < ids.length; i++) {
            Long annexId = Long.valueOf(ids[i]);
            String url = urls[i];
            picMap = new HashMap<>();
            picMap.put("type", 107);
            picMap.put("id", annexId);
            picMap.put("url", url);
            picMapList.add(picMap);
            annexBizItemList.add(new AnnexBizItem(annexId, entityId, 107));
        }
        entity.setRegPics(picMapList);
        mapper.insert(entity);
        // 更新附件为可用
        baseClient.enableAnnexStatus(annexBizItemList);
        // 发送进件
        ysRegProvider.sendYsReg(entityId);
        return JsonResult.success()
                .code(EnumSysCode.MSG_6002.getCode())
                .message(EnumSysCode.MSG_6002.getMsg())
                .build();
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public JsonResult updatePersonalRegInfo(Long id, String custName, String idCardNum, String bankType, String provMap,
                                            String cityMap, String countyMap, String address, String bankProvMap, String bankCityMap,
                                            String bankCountyMap, String bankMap, String bankCardNum, String bankPhone,
                                            Long id102, String url102, Long id103, String url103, Long id104, String url104,
                                            Long id105, String url105, Long id106, String url106, String id107, String url107,
                                            String legalCertExpire) {
        InfoYsepayRegister entity = mapper.selectById(id);
        // 校验是否存在
        if (entity == null) {
            return JsonResult.failure()
                    .code(EnumSysCode.ERR_0008.getCode())
                    .message(EnumSysCode.ERR_0008.getMsg())
                    .build();
        }
        // 进件状态为进件中（2）和进件成功（3）的时候不能修改
        if (entity.getRegStatus() == 2) {
            return JsonResult.failure()
                    .code(EnumSysCode.ERR_3022.getCode())
                    .message(EnumSysCode.ERR_3022.getMsg())
                    .build();
        }
        if (entity.getRegStatus() == 3) {
            return JsonResult.failure()
                    .code(EnumSysCode.ERR_3023.getCode())
                    .message(EnumSysCode.ERR_3023.getMsg())
                    .build();
        }
        // 更新
        entity.setCustType("O");
        entity.setCustName(custName);
        // 地址
        entity.setProvince(JsonUtil.jsonToMap(BizUtil.quot2Sign(provMap)));
        entity.setCity(JsonUtil.jsonToMap(BizUtil.quot2Sign(cityMap)));
        entity.setCounty(JsonUtil.jsonToMap(BizUtil.quot2Sign(countyMap)));
        entity.setCompanyAddr(address);
        // 法人
        entity.setLegalTel(bankPhone);
        entity.setLegalCertNo(idCardNum);
        entity.setLegalCertExpire(legalCertExpire);
        // 银行
        entity.setBankAccountNo(bankCardNum);
        entity.setBankAccountName(custName);
        Map<String, Object> tmpMap = JsonUtil.jsonToMap(BizUtil.quot2Sign(bankMap));
        entity.setBankCode(MapUtils.getString(tmpMap, "key"));
        entity.setBankName(MapUtils.getString(tmpMap, "text"));
        entity.setBankType(bankType);
        entity.setBankProvince(JsonUtil.jsonToMap(BizUtil.quot2Sign(bankProvMap)));
        entity.setBankCity(JsonUtil.jsonToMap(BizUtil.quot2Sign(bankCityMap)));
        entity.setCertNo(idCardNum);
        entity.setBankTelephoneNo(bankPhone);
        // 状态
        entity.setRegStatus(1);
        entity.setUpdateTime(DateUtil.nowLdt());
        // 附件处理
        List<AnnexBizItem> annexBizItemList = new ArrayList<>();
        // 整理进件相关图片
        List<Map<String, Object>> picMapList = new ArrayList<>();
        // 102 身份证正面
        Map<String, Object> picMap = null;
        if (id102 != null && id102 != 0) {
            picMap = new HashMap<>();
            picMap.put("type", 102);
            picMap.put("id", id102);
            picMap.put("url", url102);
            picMapList.add(picMap);
            annexBizItemList.add(new AnnexBizItem(Long.valueOf(id102), id, 102));
        }
        // 103 身份证反面
        if (id103 != null && id103 != 0) {
            picMap = new HashMap<>();
            picMap.put("type", 103);
            picMap.put("id", id103);
            picMap.put("url", url103);
            picMapList.add(picMap);
            annexBizItemList.add(new AnnexBizItem(Long.valueOf(id103), id, 103));
        }
        // 104 银行卡正面
        if (id104 != null && id104 != 0) {
            picMap = new HashMap<>();
            picMap.put("type", 104);
            picMap.put("id", id104);
            picMap.put("url", url104);
            picMapList.add(picMap);
            annexBizItemList.add(new AnnexBizItem(Long.valueOf(id104), id, 104));
        }
        // 105 银行卡反面
        if (id105 != null && id105 != 0) {
            picMap = new HashMap<>();
            picMap.put("type", 105);
            picMap.put("id", id105);
            picMap.put("url", url105);
            picMapList.add(picMap);
            annexBizItemList.add(new AnnexBizItem(Long.valueOf(id105), id, 105));
        }
        // 106 手持身份证
        if (id106 != null && id106 != 0) {
            picMap = new HashMap<>();
            picMap.put("type", 106);
            picMap.put("id", id106);
            picMap.put("url", url106);
            picMapList.add(picMap);
            annexBizItemList.add(new AnnexBizItem(Long.valueOf(id106), id, 106));
        }
        // 107 经营场所照片列表
        if (!StringUtils.isEmpty(id107)) {
            String[] ids = id107.split(",");
            String[] urls = url107.split(",");
            for (int i = 0; i < ids.length; i++) {
                Long annexId = Long.valueOf(ids[i]);
                String url = urls[i];
                picMap = new HashMap<>();
                picMap.put("type", 107);
                picMap.put("id", annexId);
                picMap.put("url", url);
                picMapList.add(picMap);
                annexBizItemList.add(new AnnexBizItem(annexId, id, 107));
            }
        }
        entity.setRegPics(picMapList);
        mapper.updateById(entity);
        // 更新附件为可用
        baseClient.enableAnnexStatus(annexBizItemList);
        // 发送进件
        ysRegProvider.sendYsReg(entity.getId());
        return JsonResult.success()
                .code(EnumSysCode.MSG_6002.getCode())
                .message(EnumSysCode.MSG_6002.getMsg())
                .build();
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public JsonResult saveEntRegInfo(String custName, String busLicense, String busLicenseExpire,
                                     String provMap, String cityMap, String countyMap, String address,
                                     String legalName, String legalCertNo, String legalTel, String legalCertExpire,
                                     String bankProvMap, String bankCityMap, String bankCountyMap, String bankMap,
                                     String bankType, String bankCardNum, String bankAccountName, String certNo, String bankPhone,
                                     Long id101, String url101,
                                     Long id102, String url102, Long id103, String url103, Long id106, String url106,
                                     String id107, String url107, Long id108, String url108, boolean samePerson) {
        Integer busiType = AccountInfo.getBusiType();
        Long busiId = AccountInfo.getBusiId();
        String shopName = AccountInfo.getShopName();
        // check 是否已完善信息
        Integer regStatus = 0;
        switch (busiType) {
            case 2:
                InfoFarmer farmer = farmerMapper.selectById(busiId);
                if (farmer != null) {
                    regStatus = farmer.getRegStatus();
                }
                break;
            case 3:
            case 4:
            case 5:
                InfoBusiness business = businessMapper.selectById(busiId);
                if (business != null) {
                    regStatus = business.getRegStatus();
                }
                break;
        }
        if (regStatus != 2) {
            return JsonResult.failure()
                    .code(EnumSysCode.ERR_3021.getCode())
                    .message(EnumSysCode.ERR_3021.getMsg())
                    .build();
        }
        //
        InfoYsepayRegister entity = new InfoYsepayRegister();
        Long entityId = idGenerator.nextId();
        // 保存
        entity.setId(entityId);
        entity.setBusiType(busiType);
        entity.setBusiId(busiId);
        entity.setUserId(AccountInfo.getUserId());
        entity.setOpenId(AccountInfo.getOpenId());
        entity.setCustType("B");
        entity.setAnotherName(shopName);
        entity.setCustName(custName);
        entity.setMerFlag("11");
        entity.setIndustry("58");
        entity.setProvince(JsonUtil.jsonToMap(BizUtil.quot2Sign(provMap)));
        entity.setCity(JsonUtil.jsonToMap(BizUtil.quot2Sign(cityMap)));
        entity.setCounty(JsonUtil.jsonToMap(BizUtil.quot2Sign(countyMap)));
        entity.setCompanyAddr(address);
        // 营业执照
        entity.setBusLicense(busLicense);
        entity.setBusLicenseExpire(busLicenseExpire);
        // 法人
        entity.setLegalName(legalName);
        entity.setLegalCertType("00");
        entity.setLegalCertNo(legalCertNo);
        entity.setLegalTel(legalTel);
        entity.setLegalCertExpire(legalCertExpire);
        // 银行
        entity.setSettleType("1");
        entity.setBankType(bankType);
        if (samePerson) {
            entity.setBankAccountName(legalName);
            entity.setCertNo(legalCertNo);
        } else {
            entity.setBankAccountName(bankAccountName);
            entity.setCertNo(certNo);
        }
        entity.setBankAccountNo(bankCardNum);
        entity.setCertType("00");
        entity.setBankTelephoneNo(bankPhone);
        entity.setBankAccountType("corporate");
        entity.setBankCardType("debit");
        Map<String, Object> tmpMap = JsonUtil.jsonToMap(BizUtil.quot2Sign(bankMap));
        entity.setBankCode(MapUtils.getString(tmpMap, "key"));
        entity.setBankName(MapUtils.getString(tmpMap, "text"));
        entity.setBankProvince(JsonUtil.jsonToMap(BizUtil.quot2Sign(bankProvMap)));
        entity.setBankCity(JsonUtil.jsonToMap(BizUtil.quot2Sign(bankCityMap)));
        // 状态
        entity.setRegStatus(1);
        entity.setCreateTime(DateUtil.nowLdt());
        // 附件处理
        List<AnnexBizItem> annexBizItemList = new ArrayList<>();
        // 整理进件相关图片
        List<Map<String, Object>> picMapList = new ArrayList<>();
        // 101 营业执照
        Map<String, Object> picMap = new HashMap<>();
        picMap.put("type", 101);
        picMap.put("id", id101);
        picMap.put("url", url101);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id101), entityId, 101));
        // 102 身份证正面
        picMap = new HashMap<>();
        picMap.put("type", 102);
        picMap.put("id", id102);
        picMap.put("url", url102);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id102), entityId, 102));
        // 103 身份证反面
        picMap = new HashMap<>();
        picMap.put("type", 103);
        picMap.put("id", id103);
        picMap.put("url", url103);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id103), entityId, 103));
        // 106 手持身份证
        picMap = new HashMap<>();
        picMap.put("type", 106);
        picMap.put("id", id106);
        picMap.put("url", url106);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id106), entityId, 106));
        // 108 开户许可证
        picMap = new HashMap<>();
        picMap.put("type", 108);
        picMap.put("id", id108);
        picMap.put("url", url108);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id108), entityId, 108));
        // 107 经营场所照片列表
        String[] ids = id107.split(",");
        String[] urls = url107.split(",");
        for (int i = 0; i < ids.length; i++) {
            Long annexId = Long.valueOf(ids[i]);
            String url = urls[i];
            picMap = new HashMap<>();
            picMap.put("type", 107);
            picMap.put("id", annexId);
            picMap.put("url", url);
            picMapList.add(picMap);
            annexBizItemList.add(new AnnexBizItem(annexId, entityId, 107));
        }
        entity.setRegPics(picMapList);
        mapper.insert(entity);
        // 更新附件为可用
        baseClient.enableAnnexStatus(annexBizItemList);
        // 发送进件
        ysRegProvider.sendYsReg(entityId);
        return JsonResult.success()
                .code(EnumSysCode.MSG_6002.getCode())
                .message(EnumSysCode.MSG_6002.getMsg())
                .build();
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public JsonResult updateEntRegInfo(Long id, String custName, String busLicense, String busLicenseExpire,
                                       String provMap, String cityMap, String countyMap, String address,
                                       String legalName, String legalCertNo, String legalTel, String legalCertExpire,
                                       String bankProvMap, String bankCityMap, String bankCountyMap, String bankMap,
                                       String bankType, String bankCardNum, String bankAccountName, String certNo, String bankPhone,
                                       Long id101, String url101,
                                       Long id102, String url102, Long id103, String url103, Long id106, String url106,
                                       String id107, String url107, Long id108, String url108, boolean samePerson) {
        //
        InfoYsepayRegister entity = mapper.selectById(id);
        // 校验是否存在
        if (entity == null) {
            return JsonResult.failure()
                    .code(EnumSysCode.ERR_0008.getCode())
                    .message(EnumSysCode.ERR_0008.getMsg())
                    .build();
        }
        // 进件状态为进件中（2）和进件成功（3）的时候不能修改
        if (entity.getRegStatus() == 2) {
            return JsonResult.failure()
                    .code(EnumSysCode.ERR_3022.getCode())
                    .message(EnumSysCode.ERR_3022.getMsg())
                    .build();
        }
        if (entity.getRegStatus() == 3) {
            return JsonResult.failure()
                    .code(EnumSysCode.ERR_3023.getCode())
                    .message(EnumSysCode.ERR_3023.getMsg())
                    .build();
        }
        // 更新
        entity.setCustType("B");
        entity.setCustName(custName);
        entity.setProvince(JsonUtil.jsonToMap(BizUtil.quot2Sign(provMap)));
        entity.setCity(JsonUtil.jsonToMap(BizUtil.quot2Sign(cityMap)));
        entity.setCounty(JsonUtil.jsonToMap(BizUtil.quot2Sign(countyMap)));
        entity.setCompanyAddr(address);
        // 营业执照
        entity.setBusLicense(busLicense);
        entity.setBusLicenseExpire(busLicenseExpire);
        // 法人
        entity.setLegalName(legalName);
        entity.setLegalCertNo(legalCertNo);
        entity.setLegalTel(legalTel);
        entity.setLegalCertExpire(legalCertExpire);
        // 银行
        entity.setBankType(bankType);
        entity.setBankAccountNo(bankCardNum);
        if (samePerson) {
            entity.setBankAccountName(legalName);
            entity.setCertNo(legalCertNo);
        } else {
            entity.setBankAccountName(bankAccountName);
            entity.setCertNo(certNo);
        }
        entity.setBankTelephoneNo(bankPhone);
        Map<String, Object> tmpMap = JsonUtil.jsonToMap(BizUtil.quot2Sign(bankMap));
        entity.setBankCode(MapUtils.getString(tmpMap, "key"));
        entity.setBankName(MapUtils.getString(tmpMap, "text"));
        entity.setBankProvince(JsonUtil.jsonToMap(BizUtil.quot2Sign(bankProvMap)));
        entity.setBankCity(JsonUtil.jsonToMap(BizUtil.quot2Sign(bankCityMap)));
        // 状态
        entity.setRegStatus(1);
        entity.setUpdateTime(DateUtil.nowLdt());
        // 附件处理
        List<AnnexBizItem> annexBizItemList = new ArrayList<>();
        // 整理进件相关图片
        List<Map<String, Object>> picMapList = new ArrayList<>();
        // 101 营业执照
        Map<String, Object> picMap = new HashMap<>();
        picMap.put("type", 101);
        picMap.put("id", id101);
        picMap.put("url", url101);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id101), id, 101));
        // 102 身份证正面
        picMap = new HashMap<>();
        picMap.put("type", 102);
        picMap.put("id", id102);
        picMap.put("url", url102);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id102), id, 102));
        // 103 身份证反面
        picMap = new HashMap<>();
        picMap.put("type", 103);
        picMap.put("id", id103);
        picMap.put("url", url103);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id103), id, 103));
        // 106 手持身份证
        picMap = new HashMap<>();
        picMap.put("type", 106);
        picMap.put("id", id106);
        picMap.put("url", url106);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id106), id, 106));
        // 108 开户许可证
        picMap = new HashMap<>();
        picMap.put("type", 108);
        picMap.put("id", id108);
        picMap.put("url", url108);
        picMapList.add(picMap);
        annexBizItemList.add(new AnnexBizItem(Long.valueOf(id108), id, 108));
        // 107 经营场所照片列表
        String[] ids = id107.split(",");
        String[] urls = url107.split(",");
        for (int i = 0; i < ids.length; i++) {
            Long annexId = Long.valueOf(ids[i]);
            String url = urls[i];
            picMap = new HashMap<>();
            picMap.put("type", 107);
            picMap.put("id", annexId);
            picMap.put("url", url);
            picMapList.add(picMap);
            annexBizItemList.add(new AnnexBizItem(annexId, id, 107));
        }
        entity.setRegPics(picMapList);
        mapper.updateById(entity);
        // 更新附件为可用
        baseClient.enableAnnexStatus(annexBizItemList);
        // 发送进件
        ysRegProvider.sendYsReg(entity.getId());
        return JsonResult.success()
                .code(EnumSysCode.MSG_6002.getCode())
                .message(EnumSysCode.MSG_6002.getMsg())
                .build();
    }

    @Override
    public JsonResult getYsRegInfo(Integer getType) throws Exception {
        QueryWrapper<InfoYsepayRegister> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("BusiType", AccountInfo.getBusiType())
                .eq("BusiId", AccountInfo.getBusiId())
                .orderByDesc("CreateTime");
        List<InfoYsepayRegister> entityList = mapper.selectList(queryWrapper);
        if (entityList == null || entityList.isEmpty()) {
            return JsonResult.failure()
                    .code(EnumSysCode.ERR_0008.getCode())
                    .message(EnumSysCode.ERR_0008.getMsg())
                    .build();
        }
        InfoYsepayRegister entity = entityList.get(0);
        InfoYseapyRegVO view = new InfoYseapyRegVO();
        BeanUtils.copyProperties(view, entity);
        // 省市区
        StringBuilder sbPcc = new StringBuilder();
        // 省
        Map<String, Object> tmpMap = entity.getProvince();
        sbPcc.append(MapUtils.getString(tmpMap, "name"));
        // 市
        tmpMap = entity.getCity();
        sbPcc.append(MapUtils.getString(tmpMap, "name"));
        // 区
        tmpMap = entity.getCounty();
        sbPcc.append(MapUtils.getString(tmpMap, "name"));
        // 省市区
        view.setPccStr(sbPcc.toString());
        // 开户行省
        tmpMap = entity.getBankProvince();
        view.setBankProvKey(MapUtils.getString(tmpMap, "key"));
        view.setBankProvText(MapUtils.getString(tmpMap, "text"));
        // 开户行市
        tmpMap = entity.getBankCity();
        view.setBankCityKey(MapUtils.getString(tmpMap, "key"));
        view.setBankCityText(MapUtils.getString(tmpMap, "text"));
        // 法人和开户人是否相同
        if (StringUtils.equals(entity.getLegalCertNo(), entity.getCertNo())) {
            view.setSamePerson(true);
        } else {
            view.setSamePerson(false);
        }
        // 营业执照是否是长期
        if (!StringUtils.isEmpty(entity.getLegalCertExpire())
                && StringUtils.equals(Const.YS_ENT_LICENSE_LONG_TERM, entity.getLegalCertExpire())) {
            view.setLicLongTerm(true);
        } else {
            view.setLicLongTerm(false);
        }
        // 图片
        if (getType != null && getType == 1) {
            List<Map<String, Object>> regPicMapList = entity.getRegPics();
            List<Map<String, Object>> obj107List = new ArrayList<>();
            for (Map<String, Object> map : regPicMapList) {
                int type = MapUtils.getIntValue(map, "type");
                switch (type) {
                    case 101:
                        Long id101 = MapUtils.getLong(map, "id");
                        tmpMap = baseClient.getOSSFileBase64ById(id101);
                        view.setB101(getImageBase64WithHeader(tmpMap, "base64"));
                        view.setId101(id101);
                        view.setUrl101(MapUtils.getString(map, "url"));
                        break;
                    case 102:
                        Long id102 = MapUtils.getLong(map, "id");
                        tmpMap = baseClient.getOSSFileBase64ById(id102);
                        view.setB102(getImageBase64WithHeader(tmpMap, "base64"));
                        view.setId102(id102);
                        view.setUrl102(MapUtils.getString(map, "url"));
                        break;
                    case 103:
                        Long id103 = MapUtils.getLong(map, "id");
                        tmpMap = baseClient.getOSSFileBase64ById(id103);
                        view.setB103(getImageBase64WithHeader(tmpMap, "base64"));
                        view.setId103(MapUtils.getLong(map, "id"));
                        view.setUrl103(MapUtils.getString(map, "url"));
                        break;
                    case 104:
                        Long id104 = MapUtils.getLong(map, "id");
                        tmpMap = baseClient.getOSSFileBase64ById(id104);
                        view.setB104(getImageBase64WithHeader(tmpMap, "base64"));
                        view.setId104(MapUtils.getLong(map, "id"));
                        view.setUrl104(MapUtils.getString(map, "url"));
                        break;
                    case 105:
                        Long id105 = MapUtils.getLong(map, "id");
                        tmpMap = baseClient.getOSSFileBase64ById(id105);
                        view.setB105(getImageBase64WithHeader(tmpMap, "base64"));
                        view.setId105(MapUtils.getLong(map, "id"));
                        view.setUrl105(MapUtils.getString(map, "url"));
                        break;
                    case 106:
                        Long id106 = MapUtils.getLong(map, "id");
                        tmpMap = baseClient.getOSSFileBase64ById(id106);
                        view.setB106(getImageBase64WithHeader(tmpMap, "base64"));
                        view.setId106(MapUtils.getLong(map, "id"));
                        view.setUrl106(MapUtils.getString(map, "url"));
                        break;
                    case 107:
                        Long id107 = MapUtils.getLong(map, "id");
                        tmpMap = baseClient.getOSSFileBase64ById(id107);
                        Map<String, Object> map107 = new HashMap<>();
                        map107.put("b107", getImageBase64WithHeader(tmpMap, "base64"));
                        map107.put("id", id107);
                        map107.put("url", MapUtils.getString(map, "url"));
                        obj107List.add(map107);
                        break;
                    case 108:
                        Long id108 = MapUtils.getLong(map, "id");
                        tmpMap = baseClient.getOSSFileBase64ById(id108);
                        view.setB108(getImageBase64WithHeader(tmpMap, "base64"));
                        view.setId108(MapUtils.getLong(map, "id"));
                        view.setUrl108(MapUtils.getString(map, "url"));
                        break;
                }
            }
            view.setList107(obj107List);
        } else {
            // 银行卡号
            view.setBankAccountNo(BizUtil.char2Star(view.getBankAccountNo(), 0, 4, '*'));
            // 身份证号
            view.setCertNo(BizUtil.char2Star(view.getCertNo(), 3, 4, '*'));
            view.setLegalCertNo(BizUtil.char2Star(view.getLegalCertNo(), 3, 4, '*'));
            // 电话号码
            view.setLegalTel(BizUtil.char2Star(view.getLegalTel(), 3, 4, '*'));
            view.setBankTelephoneNo(BizUtil.char2Star(view.getBankTelephoneNo(), 3, 4, '*'));
        }
        return JsonResult.success()
                .data(view)
                .build();
    }

    @Override
    public Map<String, Object> getYsRegStatus() {
        QueryWrapper<InfoYsepayRegister> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("BusiType", AccountInfo.getBusiType())
                .eq("BusiId", AccountInfo.getBusiId())
                .orderByDesc("CreateTime");
        List<InfoYsepayRegister> entityList = mapper.selectList(queryWrapper);
        Map<String, Object> resultMap = new HashMap<>();
        if (entityList == null || entityList.isEmpty()) {
            resultMap.put("regStatus", -1);
        } else {
            InfoYsepayRegister entity = entityList.get(0);
            resultMap.put("regStatus", entity.getRegStatus());
            resultMap.put("regResult", entity.getRegResult());
            resultMap.put("custType", entity.getCustType());
            resultMap.put("bindWechatSuccess", entity.getBindWechatBiz());
        }
        return resultMap;
    }


    @Transactional(rollbackFor = Throwable.class)
    @Override
    public ResRegister ysReg(Long id) throws Exception {
        // 获取数据
        InfoYsepayRegister entity = mapper.selectById(id);
        // check 是否为未进件状态，其他状态直接返回。
        if (entity == null || entity.getRegStatus() != 1) {
            return null;
        }
        // 创建view
        YsepayRegister view = new YsepayRegister();
        BeanUtils.copyProperties(view, entity);
        view.setAnotherName(view.getCustName());
        view.setMerchantNo(entity.getMerchantNo1());
        view.setProvince(MapUtils.getString(entity.getProvince(), "name"));
        view.setCity(MapUtils.getString(entity.getCity(), "name"));
        view.setBankProvince(MapUtils.getString(entity.getBankProvince(), "text"));
        view.setBankCity(MapUtils.getString(entity.getBankCity(), "text"));
        // 整理上传数据
        List<Map<String, Object>> picMapList = new ArrayList<>();
        // 临时Map，用于接收读取到的base64文件
        Map<String, Object> tmpMap;
        // 图片Map
        Map<String, Object> regPicMap;
        int num = 0;
        for (Map<String, Object> picMap : entity.getRegPics()) {
            long annexId = MapUtils.getLongValue(picMap, "id");
            int type = MapUtils.getIntValue(picMap, "type");
            tmpMap = baseClient.getOSSFileBase64ById(annexId);
            regPicMap = new HashMap<>();
            regPicMap.putAll(picMap);
            regPicMap.put("base64", MapUtils.getString(tmpMap, "base64"));
            String picType = getUploadPicType(type);
            if (StringUtils.equals(picType, "MY107")) {
                if (num == 0) {
                    regPicMap.put("upload_type", "34");
                } else if (num == 1) {
                    regPicMap.put("upload_type", "50");
                } else if (num == 2) {
                    regPicMap.put("upload_type", "51");
                }
                num++;
            } else {
                regPicMap.put("upload_type", picType);
            }
            picMapList.add(regPicMap);
        }
        // 生成合同
        byte[] contract = generateContract(entity.getCustType(), entity.getAnotherName(),
                entity.getLegalTel(), entity.getLegalName());
        // 压缩图片
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Thumbnails.of(new ByteArrayInputStream(contract)).scale(0.6f).outputQuality(1).toOutputStream(bos);
        contract = bos.toByteArray();
        // 获取token
        String token = paidHelper.getUploadToken();
        // 上传合同
        boolean success = paidHelper.upload(token, "31", contract);
        // 合同上传失败直接退出
        if (!success) {
            return null;
        }
        // 上传附件
        for (Map<String, Object> picMap : picMapList) {
            byte[] bs = Base64Util.decode2Bytes(MapUtils.getString(picMap, "base64"));
            success = paidHelper.upload(token,
                    MapUtils.getString(picMap, "upload_type"),
                    bs
            );
            // 附件上传失败直接退出
            if (!success) {
                return null;
            }
        }
        view.setBankAccountName(view.getCustName());
        // 进件
        ResRegister resRegister = paidHelper.register(token, view);
        if (resRegister.getCode() == 10000) {
            entity.setUserCode(resRegister.getUserCode());
            entity.setUserStatus(resRegister.getUserStatus());
            entity.setCustId(resRegister.getCustId());
            entity.setRegStatus(2);
            ysRegisterResultQueryProvider.sendYsRegisterResultQuery(entity.getId());
        } else {
            entity.setRegResult(resRegister.getData());
            entity.setRemark(resRegister.getSubMsg());
            if (StringUtils.equals(Const.YS_REG_ACQ_CERT_USED_TIMES, resRegister.getSubCode())) {
                entity.setRegStatus(99);
            } else {
                entity.setRegStatus(4);
                // 发送进件失败消息
                String openId = entity.getOpenId();
                Long userId = entity.getUserId();
                String title = "审核结果通知";
                String content = "您提交的收款账号信息审核失败，请重新提交。";
                Map<String, String> bizData = new HashMap<>();
                bizData.put("openId", openId);
                bizData.put("reviewResult", "审核失败");
                bizData.put("notification", "您的收款账户信息审核失败，请点击修改");
                sysMsgProvider.sendSysMessage(1, 9010, bizData, userId, title, content, 0L);
            }
        }
        entity.setUpdateTime(DateUtil.nowLdt());
        mapper.updateById(entity);
        return resRegister;
    }

    @Override
    public JsonResult searchYsReg(String merchantNo) throws Exception {
        String str = paidHelper.searchRegister(merchantNo);
        return JsonResult.success()
                .data(str)
                .build();
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public ResSearchReg searchYsRegByMerchantNo(InfoYsepayRegister entity) throws Exception {
        // 获取数据
//        InfoYsepayRegister entity = this.getOne(new QueryWrapper<InfoYsepayRegister>().eq("MerchantNo1", merchantNo));
        // check 是否为进件中状态，其他状态直接返回。
        if (entity == null || entity.getRegStatus() != 2) {
            return null;
        }
        String result = paidHelper.searchRegister(entity.getMerchantNo1());
        ResSearchReg searchReg = JsonUtil.jsonToObject(result, ResSearchReg.class);
        // reg log
//        BizYespayRegLog regLog = bizYespayRegLogService.getOne(new QueryWrapper<BizYespayRegLog>()
//                .eq("MerchantNo", merchantNo));

        boolean success = false;
        if (searchReg.getCode() == 10000) {
            // 访问成功
            if (StringUtils.equals(searchReg.getUserStatus(), YsConst.YS_REG_SUCCESS_USER_STATUS)) {
                // 进件生效
                entity.setRegStatus(3);
                entity.setRegTime(DateUtil.nowLdt());
                entity.setUserCode(searchReg.getUserCode());
                entity.setCustId(searchReg.getCustId());
//                regLog.setRegSuccess(1);
                success = true;
            } else {
                // 进件失败
                entity.setRegStatus(4);

//                regLog.setRegSuccess(0);
                success = false;
            }

            entity.setUserStatus(searchReg.getUserStatus());
            entity.setRegResult(searchReg);

            // reg log
//            regLog.setUserStatus(searchReg.getUserStatus());
//            regLog.setCustStatus(searchReg.getCustStatus());
//            regLog.setIsNeedContract(String.valueOf(searchReg.isNeedContract()));
        } else if (searchReg.getCode() == 40004){
            // 此情况为进件异常，银盛没有收到进件信息，只能等进件补偿任务做补偿，故暂时不发送进件失败消息
            success = true;
        }

        // 如果进件结果失败，发送微信订阅消息给用户
        if (!success) {
            String openId = entity.getOpenId();
            Long userId = entity.getUserId();
            sendOnlineYsRegFail(userId, openId);
        }
        entity.setUpdateTime(DateUtil.nowLdt());
        mapper.updateById(entity);
//        bizYespayRegLogService.updateById(regLog);
        return searchReg;
    }

    // 发送线上进件失败 微信消息
    @Override
    public void sendOnlineYsRegFail(Long userId, String openId) {
        String title = "审核结果通知";
        String content = "您提交的收款账号信息审核失败，请重新提交。";
        Map<String, String> bizData = new HashMap<>();
        bizData.put("openId", openId);
        bizData.put("reviewResult", "审核失败");
        bizData.put("notification", "您的收款账户信息审核失败，请点击修改。");
        sysMsgProvider.sendSysMessage(1, 9010, bizData, userId, title, content, 0L);
    }

    // 发送线下进件成功 微信消息 for my boss
    @Override
    public void sendOfflineYsRegSuccess(Long userId, String openId) {
        String title = "审核结果通知";
        String content = "您的收款账户信息已审核通过。";
        Map<String, String> bizData = new HashMap<>();
        bizData.put("openId", openId);
        bizData.put("reviewResult", "审核成功");
        bizData.put("notification", "您的收款账户信息已审核通过，请点击查看。");
        sysMsgProvider.sendSysMessage(1, 9011, bizData, userId, title, content, 0L);
    }

    @Override
    public List<Long> getEntityForReg(int limit, int minutes) {
        return mapper.getEntityForReg(limit, minutes);
    }

    @Override
    public void ysRegNotify(String usercode, String custname, String custid, String user_status, String cust_status, String merchant_no) {
        if (user_status == null)
            return;

        Integer regStatus = 0;
        if (user_status.equals("生效"))
            regStatus = 3;
        else
            regStatus = 4;

        this.update(new UpdateWrapper<InfoYsepayRegister>()
                .eq("UserCode", usercode)
                .eq("CustId", custid)
                .eq("MerchantNo", merchant_no)
                .set("UserStatus", user_status)
                .set("CustStatus", cust_status)
                .set("RegStatus", regStatus));
    }

    /**
     * 获取带头的Base64
     *
     * @param map
     * @param key
     * @return
     */
    private String getImageBase64WithHeader(Map<String, Object> map, String key) {
        StringBuilder sb = new StringBuilder();
        String base64 = MapUtils.getString(map, key);
        if (!StringUtils.isEmpty(base64)) {
            sb.append(Const.BASE64_IMAGE_HEADER);
            sb.append(base64);
        }
        return sb.toString();
    }

    /**
     * 转换上传类型
     *
     * @param type
     * @return
     */
    private String getUploadPicType(int type) {
        String picType = "";
        switch (type) {
            case 101:
                picType = "19";
                break;
            case 102:
                picType = "00";
                break;
            case 103:
                picType = "30";
                break;
            case 104:
                picType = "35";
                break;
            case 105:
                picType = "36";
                break;
            case 106:
                picType = "33";
                break;
            case 107:
                picType = "MY107";
                break;
            case 108:
                picType = "37";
                break;
        }
        return picType;
    }


    @Override
    public byte[] generateContract(String type, String partyB, String phone, String legalName) throws Exception {
        byte[] bytes = new byte[0];
        String strTime = DateUtil.formatNow("yyyy年MM月dd日");
        Map<String, Object> map;
        if (StringUtils.equals("O", type)) {
            String regPer = ysProperties.getRegPersonal();
            PositionConfig conf = JsonUtil.jsonToObject(regPer, PositionConfig.class);
            Font f = new Font(conf.getFontName(), Font.PLAIN, conf.getFontSize());
            // 创建写入list
            List<ImageUtil.WriteWord> list = new ArrayList<>();
            list.add(new ImageUtil.WriteWord(conf.getUpNameX(), conf.getUpNameY(), partyB, f, Color.BLACK));
            list.add(new ImageUtil.WriteWord(conf.getUpPhoneX(), conf.getUpPhoneY(), phone, f, Color.BLACK));
            list.add(new ImageUtil.WriteWord(conf.getDownDate1X(), conf.getDownDate1Y(), strTime, f, Color.BLACK));
            list.add(new ImageUtil.WriteWord(conf.getDownDate2X(), conf.getDownDate2Y(), strTime, f, Color.BLACK));
            list.add(new ImageUtil.WriteWord(conf.getDownNameX(), conf.getDownNameY(), partyB, f, Color.BLACK));
            // 获取底图
            map = baseClient.getSecretFileBase64Map(1L, 109);
            String base64 = MapUtils.getString(map, "base64");
            Image image = ImageUtil.getImageFromBytes(Base64Util.decode2Bytes(base64));
            bytes = ImageUtil.writeWords(image, list, "png");
        } else {
            String regEnt = ysProperties.getRegEnterprise();
            PositionConfig conf = JsonUtil.jsonToObject(regEnt, PositionConfig.class);
            Font f = new Font(conf.getFontName(), Font.PLAIN, conf.getFontSize());
            // 创建写入list
            List<ImageUtil.WriteWord> list = new ArrayList<>();
            list.add(new ImageUtil.WriteWord(conf.getUpNameX(), conf.getUpNameY(), partyB, f, Color.BLACK));
            list.add(new ImageUtil.WriteWord(conf.getUpPhoneX(), conf.getUpPhoneY(), phone, f, Color.BLACK));
            list.add(new ImageUtil.WriteWord(conf.getDownDate1X(), conf.getDownDate1Y(), strTime, f, Color.BLACK));
            list.add(new ImageUtil.WriteWord(conf.getDownDate2X(), conf.getDownDate2Y(), strTime, f, Color.BLACK));
            list.add(new ImageUtil.WriteWord(conf.getDownNameX(), conf.getDownNameY(), partyB, f, Color.BLACK));
            list.add(new ImageUtil.WriteWord(conf.getLegalNameX(), conf.getLegalNameY(), legalName, f, Color.BLACK));
            // 获取底图
            map = baseClient.getSecretFileBase64Map(1L, 110);
            String base64 = MapUtils.getString(map, "base64");
            Image image = ImageUtil.getImageFromBytes(Base64Util.decode2Bytes(base64));
            bytes = ImageUtil.writeWords(image, list, "png");
        }
        return bytes;
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public List<Map<String, Object>> getOffLineRegList(String dateTime) throws Exception {
        // 1.计算当日时间上限下限
        LocalDate localDate = DateUtil.parseLd(dateTime, "yyyy-MM-dd");
        LocalDateTime startTime = LocalDateTime.of(localDate, LocalTime.MIN);
        LocalDateTime endTime = LocalDateTime.of(localDate, LocalTime.MAX);
        // 2.修改当日线上注册成功的进件数据为5线下进件中
        UpdateWrapper<InfoYsepayRegister> updateWrapper = new UpdateWrapper<>();
        updateWrapper.isNotNull("RegTime")
                .ge("RegTime", startTime)
                .le("RegTime", endTime)
                .in("RegStatus", 3);
        InfoYsepayRegister updateEntity = new InfoYsepayRegister();
        updateEntity.setRegStatus(5);
        updateEntity.setUpdateTime(DateUtil.nowLdt());
        mapper.update(updateEntity, updateWrapper);
        // 3.查询当日线上注册成功的进件数据
        List<InfoYsepayRegister> entityList = mapper.getOffLineRegList(startTime, endTime);
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (InfoYsepayRegister entity : entityList) {
            YsOffLineRegVO view = new YsOffLineRegVO();
            BeanUtils.copyProperties(view, entity);
            // 拼接详细地址
            // 省市区
            StringBuilder sb = new StringBuilder();
            // 省
            Map<String, Object> tmpMap = entity.getProvince();
            sb.append(MapUtils.getString(tmpMap, "name", ""));
            // 市
            tmpMap = entity.getCity();
            sb.append(MapUtils.getString(tmpMap, "name", ""));
            sb.append(entity.getCompanyAddr());
            // 地址
            view.setCompanyAddr(sb.toString());
            resultList.add(view.toMap());
        }
        return resultList;
    }

    @Override
    public Map<String, Object> updateOffLineRegResult(List<DataSixUpload> dataList) {
        Map<String, Object> resultMap = new HashMap<>();
        int success = 0;
        List<String> faultList = new ArrayList<>();
        for (DataSixUpload data : dataList) {
            // 根据UserCode查询数据
            QueryWrapper<InfoYsepayRegister> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("UserCode", data.getUserCode());
            InfoYsepayRegister entity = mapper.selectOne(queryWrapper);
            if (entity != null && entity.getRegStatus() == 5) {
                if (StringUtils.equals("Y", data.getResult())) {
                    // 线下进件成功
                    entity.setRegStatus(6);
                    entity.setUpdateTime(DateUtil.nowLdt());
                    mapper.updateById(entity);
                    sendOfflineYsRegSuccess(entity.getUserId(), entity.getOpenId());
                } else {
                    // 线下进件失败
                    entity.setRegStatus(7);
                    entity.setUpdateTime(DateUtil.nowLdt());
                    mapper.updateById(entity);
                }
                success++;
            } else {
                if (entity == null) {
                    faultList.add(String.format(
                            "%s, %s, null, UserCode is not exists.",
                            data.getUserCode(),
                            data.getResult()
                    ));
                } else {
                    faultList.add(String.format(
                            "%s, %s, %s, UserCode is not exists.",
                            data.getUserCode(),
                            data.getResult(),
                            entity.getRegStatus()
                    ));
                }
            }
        }
        resultMap.put("success", success);
        resultMap.put("faultList", faultList);
        return resultMap;
    }

    @Override
    public List<InfoYsepayRegister> getEntityByRegStatus(Integer regStatus, int limit, int minutes) {
        return mapper.getEntityByRegStatus(regStatus, limit, minutes);
    }
}
